package kr.co.graviti.adm.bbs.action;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import kr.co.graviti.adm.common.dao.AdmCommonDAO;
import kr.co.graviti.common.action.BaseFuncAction;
import kr.co.graviti.common.util.CommonUtil;

public class AdmBbsInsertFormAction extends BaseFuncAction{

	/** 공지사항 글쓰기 폼 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response 
	 * @return
	 * @throws Exception
	 */
	public ActionForward notice(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,HttpServletResponse response)
	        throws Exception {
		
		boolean _result = new AdmBbsInsertFormAction().boardInsert(request, response);
		String returnfoward = "";
		if(_result){
			returnfoward = CommonUtil.strNullChk(request.getParameter("board_type"));
		}else{
			returnfoward = "fail";
		}
		
		return mapping.findForward(returnfoward);
	}
	
	public boolean boardInsert(HttpServletRequest request,HttpServletResponse response) throws Exception{
		
		boolean _result = true;
		HashMap req = null;
		HashMap bbsSort = new HashMap();
		req = CommonUtil.getRequest(request);
		String ibatisNm = "admBbs";
		AdmCommonDAO dao = new AdmCommonDAO();
		
		/* 게시판 기본정보 */
		int bbsCnt = dao.getIntegerDAO(req, ibatisNm+".selectBbsSortCount");
		if(bbsCnt > 0){
			bbsSort = dao.getHashMapDAO(req, ibatisNm+".selectBbsSort");
			req.put("board_cd", bbsSort.get("BOARD_CD"));
		}else{
			String alertMsg = CommonUtil.printAlertBack("잘못된 페이지 정보 입니다..");	
			request.setAttribute("alertMsg", alertMsg);
			_result = false;
		}
		
		bbsSort.put("thumnail", FILE_TYPE_THUMNAIL);
		bbsSort.put("image", FILE_TYPE_IMAGE);
		bbsSort.put("document", FILE_TYPE_DOCUMENT);
		bbsSort.put("movie", FILE_TYPE_MOVIE);
		
		request.setAttribute("req", req);
		request.setAttribute("bbsSort", bbsSort);
		return _result;
	}
}
